import React from 'react'
import axios from 'axios'
export default function Index() {
    let timer = null
    const handelStart = () => {
        let success_count = 0
        let error_count = 0
        const params = {
            'lang': 'cn',
            'extId': 'circleswap',
            'x-b3-traceid': 'f4243c48b314e75756df838da5bc4bbc'
        }
        timer = setInterval(() => {
            let vtoken = '01ff94b3422cb21fafc' + String(Math.random() * 8610368976499 + 1000000000000).split(0, 13)
            axios.get('https://www.defibox.com/dgg/heco/up', { params: { ...params, vtoken } }).then(res => {
                success_count++
            }).catch(err => {
                error_count++
            })
            console.log(`刷票成功：${success_count} 次  失败：${error_count} 次`)
        }, 1000)
    }

    const handelStop = () => {
        clearInterval(timer)
        alert('停止刷票')
    }

    return (
        <div>
            <button onClick={handelStart}>开始刷票</button>
            <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
            <button onClick={handelStop}>停止刷票</button>
        </div>
    )
}
